<template>
    <div class="login-wrap">
        <div class="top">
            <div class="header">
                <a href="/">
                    <span class="title">Loongson Project</span>
                </a>
            </div>
            <div class="desc">
                Loongson Project基于龙芯的项目管理申报平台
                <span class="login-tips"> &copy; 2020 云龙-云征  </span>
            </div>
        </div>
        <div class="ms-login">
            <div class="ms-title">注册</div>
            <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <el-input v-model="param.username" placeholder="username">
                        <el-button slot="prepend" icon="el-icon-lx-people"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="userphone">
                    <el-input v-model="param.userphone" placeholder="phone number">
                        <el-button slot="prepend" icon="el-icon-phone"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                            type="password"
                            placeholder="password"
                            v-model="param.password"
                            @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="passwordagain">
                    <el-input
                            type="password"
                            placeholder="password again"
                            v-model="param.passwordagain"
                            @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="verification">
                    <el-row>
                        <el-col :span="15">
                            <el-input
                                    placeholder="verification"
                                    v-model="param.verification"
                            >
                            </el-input>
                        </el-col>
                        <el-col :span="7" style="margin-left: 6px">
                            <el-button style="width: 100px" @click="getver">获取验证码</el-button>
                        </el-col>
                    </el-row>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()">注册</el-button>
                </div>
                <div class="register-tips" @click="gotoLogin">已有账号？去登录</div>
            </el-form>
        </div>
    </div>
</template>

<script>
  export default {
    name: 'register',
    data: function() {
      return {
        identifyCode: '',
        param: {
          userphone:'',
          username: '',
          password: '',
          passwordagain:'',
          verification:''
        },
        rules: {
          username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
          userphone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
          password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
          passwordagain: [{ required: true, message: '请再次输入密码', trigger: 'blur' }],
          verification: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
        },
      };
    },
    mounted () {
      this.createdCode()
    },
    methods: {
      getver(){
        if(this.param.password===this.param.passwordagain){
          this.$http.get('/user/register/phone',{
            params:{
              userPhone: this.param.userphone
            }
          }).then(res=>{
            if(res){
              console.log('获取成功请等待')
            }
          })
        }else {
          alert('两次密码不一致，重新确认密码');
        }
      },
      register(){

      },
      submitForm() {
        this.$refs.login.validate(valid => {
          if (valid) {
            this.$http.post('/user/register',{
              captcha:this.param.verification,
              realname:this.param.username,
              password:this.param.password,
              userPhone:this.param.userphone,
            }).then( res => {
              if (res) {
                this.$message.success('注册成功');
                localStorage.setItem('ms_username', this.param.username);
                this.$router.push('/login');
              }
            })
          } else {
            this.$message.error('请输入手机号和密码');
            console.log('error submit!!');
            return false;
          }
        });
      },
      gotoLogin(){
        this.$router.push('/login');
      }
    },
  };
</script>

<style  lang="less" scoped>
    .s-canvas {
        height: 38px;
        cursor: pointer;
    }
    .s-canvas canvas{
        margin-top: 1px;
        margin-left: 8px;
    }
    .login-wrap {
        position: relative;
        width: 100%;
        height: 100%;
        background-image: url(../../assets/img/login-bg.jpg);
        background-size: 100%;
    }
    .ms-title {
        width: 100%;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        color: #fff;
        border-bottom: 1px solid #ddd;
    }
    .ms-login {
        position: absolute;
        left: 50%;
        top: 58%;
        width: 350px;
        margin: -190px 0 0 -175px;
        border-radius: 5px;
        background: rgba(255, 255, 255, 0.3);
        overflow: hidden;
    }
    .ms-content {
        padding: 30px 30px ;
    }
    .login-btn {
        text-align: center;
    }
    .register-tips {
        float: right;
        font-size: 12px;
        line-height: 14px;
        color: #fff;
    }
    .login-btn button {
        width: 100%;
        height: 36px;
        margin-bottom: 10px;
    }
    .login-tips {
        color: rgba(0, 0, 0, 0.45);
        font-size: 12px;
        line-height: 30px;
        text-align: center;
    }
    .top {
        padding-top: 130px;
        text-align: center;

    .header {
        height: 44px;
        line-height: 44px;
        background-color:transparent;
    .title {
        font-size: 33px;
        color: rgba(0, 0, 0, .85);
        font-family: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
        font-weight: 600;
        position: relative;
        top: 2px;
    }
    }
    .desc {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.45);
        margin-top: 15px;
        margin-bottom: 40px;
    }
    }
</style>
